<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设备运行日志</div>
                <div class="layui-card-body">
                    <div style="margin-bottom: 10px;">
                        <div class="layui-input-item" style="float:left;padding-right:10px;">
                            <form class="layui-form">
                                <div class="layui-inline">
                                    <input id="search-tunnel-name" type="text"
                                           placeholder="请输入建筑群" class="layui-input layui-input-search">
                                </div>
                                <div class="layui-inline">
                                    <input id="search-device-abbr" type="text"
                                           placeholder="请输入设备简称" class="layui-input layui-input-search">
                                </div>
                                <div class="layui-inline">
                                    <input id="search-content" type="text"
                                           placeholder="请输入日志内容" class="layui-input layui-input-search">
                                </div>
                                <div class="layui-inline">
                                    <a id="btn-search" class="layui-btn">查找</a>
                                </div>
                            </form>
                        </div>
                        <div style="float:right;">
                            <!--<a id="btn-add" class="layui-btn">添加</a>-->
                            <a id="btn-refresh" class="layui-btn layui-btn-primary">刷新</a>
                        </div>
                        <div style="clear:both;"></div>
                    </div>
                    <table class="layui-hide" id="run-log-table" lay-filter="run-log-table"></table>
                    <script type="text/html" id="toolbar-operation">
                        <!--<a class="layui-btn layui-btn-xs" lay-event="edit">详情</a>-->
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="run-log-form">
    <div class="layui-card">
        <div class="layui-card-header">运行日志详情</div>
        <div class="layui-card-body">
            <form class="layui-form" action="#" lay-filter="run-log-form">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label">*IOT设备编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="iotDeviceCode" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*建筑群ID</label>
                    <div class="layui-input-block">
                        <input type="number" name="tunnelId" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*建筑群</label>
                    <div class="layui-input-block">
                        <input type="text" name="tunnelName" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*区域ID</label>
                    <div class="layui-input-block">
                        <input type="number" name="locationId" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*区域简称</label>
                    <div class="layui-input-block">
                        <input type="text" name="locationName" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*设备ID</label>
                    <div class="layui-input-block">
                        <input type="number" name="deviceId" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*设备简称</label>
                    <div class="layui-input-block">
                        <input type="text" name="deviceAbbr" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*设备编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="deviceCode" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备代号</label>
                    <div class="layui-input-block">
                        <input type="number" name="deviceNo" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备系统</label>
                    <div class="layui-input-block">
                        <input type="text" name="deviceSystem" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备类型</label>
                    <div class="layui-input-block">
                        <input type="text" name="deviceType" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*日志内容</label>
                    <div class="layui-input-block">
                        <input type="text" name="content" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">天气</label>
                    <div class="layui-input-block">
                        <input type="text" name="weather" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">温度</label>
                    <div class="layui-input-block">
                        <input type="number" name="temperature" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">*日志时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="logTime" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="form-submit">确定</button>
                </div>
            </form>
        </div>
    </div>
</script>
<script src="/layui/layui.js"></script>
<script>
    layui.config({
        base: '/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'laydate'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var popupIndex;


        table.render({
            elem: '#run-log-table',
            url: 'run-logs',
            title: '',
            skin: 'line',
            cols: [[
                /*{field: 'iotDeviceCode', title: 'IOT设备编码'},*/
                {field: 'tunnelName', title: '建筑群', width: 100},
                {field: 'locationName', title: '区域简称', width: 100},
                {field: 'deviceAbbr', title: '设备简称', width: 150},
                {field: 'deviceCode', title: '设备编码', width: 180},
                {field: 'deviceNo', title: '设备代号', width: 100},
                {field: 'deviceSystem', title: '设备系统', width: 100},
                {field: 'deviceType', title: '设备类型', width: 100},
                {field: 'content', title: '日志内容', width: 120},
                {field: 'weather', title: '天气', width: 80},
                {field: 'temperatureText', title: '温度', width: 80},
                {field: 'logTime', title: '发生时间', width: 180},
                {fixed: 'right', title: '操作', toolbar: '#toolbar-operation'}
            ]],
            page: true
        });

        function showRunLogForm() {
            popupIndex = admin.popupRight({
                area: '360px',
                success: function () {
                    var formHtml = $('#run-log-form').html();
                    $('#' + this.id).html(formHtml);
                    form.render();
                    laydate.render({
                        elem: '#log-time'
                    });
                }
            });
            return popupIndex;
        }

        function closePopupForm() {
            if (popupIndex) {
                layer.close(popupIndex);
            }
        }

        function search() {
            table.reload('run-log-table', {
                where: {
                    tunnelName: $('#search-tunnel-name').val(),
                    deviceAbbr: $('#search-device-abbr').val(),
                    content: $('#search-content').val(),
                },
                page: {
                    curr: 1
                }
            });
        }

        $(document).on('keypress', function (e) {
            if (e.which == 13) {
                search();
            }
        });

        $("#btn-search").on('click', function () {
            search();
        });

        $("#btn-add").on('click', function () {
            popupIndex = showRunLogForm();
        });

        $("#btn-refresh").on('click', function () {
            table.reload('run-log-table');
            layer.msg('表格已刷新');
        });

        table.on('tool(run-log-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除该记录吗？', function (index) {
                    $.ajax({
                        url: 'run-logs/' + data.id,
                        type: 'DELETE',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.msg('删除成功');
                                table.reload('run-log-table');
                            } else {
                                layer.msg('删除失败');
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                showRunLogForm();
                form.val('run-log-form', data);
            }
        });

        form.on('submit(form-submit)', function (data) {
            $.ajax({
                url: 'run-logs',
                type: 'PUT',
                data: data.field,
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg('操作成功');
                        table.reload('run-log-table');
                    } else {
                        layer.msg('提交失败');
                        console.error('提交失败');
                    }
                }
            });
            closePopupForm();
            return false;
        });

    });
</script>
</body>
</html>